<?php
$loader->requireOnce('includes/ManagerDashboard/Portlet.class.php');
class PortletPatientClass extends Portlet {
	
	function PortletPatientClass($name, $dateRange) {
		$this->name = $name;
		$this->dateRange = $dateRange;
		$this->_db = $GLOBALS['frame']['adodb']['db'];
	}
	
	protected function collectData() {
		$sql = "SELECT class, count(distinct(person_id)) num
				FROM patient 
				INNER JOIN ticket ON (patient.person_id = ticket.patient_id)
				WHERE date(closed) <= '$this->endDate'
				AND date(closed) >= '$this->startDate'
				GROUP BY class";
		$result = $this->_db->GetAll($sql);
		$i = 0;
		foreach ($result as $row){
			// Remember to use INTEGER data for the chart value (string will not be rendered)
			if ($row['class'] == '') {
				$row['class'] = "N/A";
			}
			$this->values[$i] = new OFC_Charts_Pie_Value((int)($row['num']), $row['class']);
			$i++;	
		}		
	}
	
	protected function buildChart() {
		// Create chart object and set backgound color
		$this->chart = new OFC_Chart();
		$this->chart->set_bg_colour("#FEFEFE");
		// Create chart title object and pass css param
		$title = new OFC_Elements_Title($this->name);
		$title->set_style("font-size: 13px; font-weight: bold; padding-bottom: 10px; color: #00248E");
		// Create chart object (each type is an object) and set value
		$pie = new OFC_Charts_Pie();
		$pie->set_start_angle(35);
		$pie->set_animate(true);
		$pie->set_values($this->values);
		$pie->set_colours(array("#00DD00", "#FFCC11", "#BE44E3", "#EE0000"));
		$pie->set_tooltip(L10nHelper::_('Patient %s above %s',"class #label# (#percent#)<br>#val#","#total#"));
		// Add all of them to chart object
		$this->chart->x_axis = null;
		$this->chart->set_title($title);
		$this->chart->add_element($pie);
	}
	
}
?>